package facilius.controller.action.curso;

import facilius.model.ServiceLocator;
import facilius.model.pojo.Curso;
import java.util.Map;
import org.mentawai.core.BaseAction;

/**
 *
 * @author Graciano
 */
public class CursoCreateAction extends BaseAction{

    @Override
    public String execute() throws Exception {
        String consequence = ERROR;
        try {

            Curso curso = new Curso();
            curso.setDescricao(input.getString("descricao"));
            Map<String,String> errors = ServiceLocator.getCursoService().validateForCreate(curso);
            if (errors != null && errors.get("valido").equalsIgnoreCase("s")){
                ServiceLocator.getCursoService().create(curso);
                consequence = SUCCESS;
            }else{
                output.setValue("formAction", "CursoCreate.mtw");
            }
            output.setValue("errors", errors);
            
        } catch (Exception e) {
            e.printStackTrace();
        }
        return consequence;
    }

}
